package ui.panels
{
	import events.GestureEvent;
	
	import flash.display.Bitmap;
	import flash.text.TextField;
	
	import global.Managers;
	
	import lang.LanguageManager;
	
	import resources.Resources;
	
	import ui.components.Button;
	
	import utils.TextUtil;
	
	import vo.DishVO;

	public class RecipeDetailPanel extends AbstractPanel
	{
		private var _image					: Bitmap;
		private var _txtName				: TextField;
		private var _txtType				: TextField;
		private var _txtPrice				: TextField;
		private var _txtDescribe			: TextField;
		private var _btnOK					: Button;
		private var _btnCancel				: Button;
		
		private var _value					: DishVO;
		private var _priceUnitName			: String;
		
		public function RecipeDetailPanel()
		{
			super(PanelType.RECIPE_DETAIL);
			
			_bg.bitmapData = Managers.resourceManager.getBitmapData(Resources.PANEL_RECIPE_DETAIL_BG);
			
			_image = new Bitmap();
			_image.y = 10;
			addChild(_image);
			
			_txtName = TextUtil.getTextFieldEasy("");
			_txtName.x = 50;
			_txtName.y = 250;
			addChild(_txtName);
			
			_txtType = TextUtil.getTextFieldEasy("");
			_txtType.x = 250;
			_txtType.y = 250;
			addChild(_txtType);
			
			_txtPrice = TextUtil.getTextFieldEasy("");
			_txtPrice.x = 50;
			_txtPrice.y = 275;
			addChild(_txtPrice);
			
			_txtDescribe = TextUtil.getTextFieldEasy("");
			_txtDescribe.x = 50;
			_txtDescribe.y = 300;
			addChild(_txtDescribe);
			
			_btnOK = new Button(1, Managers.languageManager.getLanguageText("order"), 150, 40, "", orderHandler);
			_btnOK.x = this.width - 160;
			_btnOK.y = this.height - 100;
			_btnOK.addListener(this);
			addChild(_btnOK);
			
			_btnCancel = new Button(2, Managers.languageManager.getLanguageText("cancel"), 150, 40, "", cancelHandler);
			_btnCancel.x = this.width - 160;
			_btnCancel.y = this.height - 50;
			_btnCancel.addListener(this);
			addChild(_btnCancel);
		}
		private function orderHandler(event:GestureEvent):void {
			Managers.billManager.addDish(_value.id);
			Managers.panelManager.close(_type);
		}
		private function cancelHandler(event:GestureEvent):void {
			Managers.panelManager.close(_type);
		}
		private function updateView():void {
			_image.bitmapData = Managers.resourceManager.getBitmapData(_value.image);
			_image.width = _image.width * (200 / _image.height);
			_image.height = 200;
			_image.x = (this.width - _image.width) / 2;
			_txtName.htmlText = _value.name;
			_txtType.text = Managers.dishManager.getTypeName(_value.type);
			_txtPrice.text = _value.price + " " + Managers.languageManager.getLanguageText(_priceUnitName);
			_txtDescribe.htmlText = _value.describe;
		}
		
		public function update(value:DishVO, priceUnitName:String):void {
			_value = value;
			_priceUnitName = priceUnitName;
			updateView();
		}
		override public function switchLanguage(toLanguage:int):void {
			super.switchLanguage(toLanguage);
			
			if(toLanguage == _currentLanguage) return;
			_currentLanguage = toLanguage;
			var manager:LanguageManager = Managers.languageManager
			
			_btnOK.text = manager.getLanguageText("order");
			_btnCancel.text = manager.getLanguageText("cancel");
		}
	}
}